package com.book.lizhi;

import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.book.lizhi.database.DataBaseMannager;
import com.book.lizhi.http.AppRequest;
import com.book.lizhi.http.FakeX509TrustManager;
import com.book.lizhi.http.OnHttpListener;
import com.book.lizhi.model.ArticleModel;

public class BaseActivity extends ActionBarActivity {
	public void sendGetRequest(String url, OnHttpListener listener) {
		if (listener != null) {
			listener.onHttpStart();
			String response = AppApplication.instance.jsonCache.getJsonStr(url);
			if (!TextUtils.isEmpty(response)) {
				listener.onResponse(true,url, response);
				return;
			}
		}
		FakeX509TrustManager.allowAllSSL();
		AppRequest request = new AppRequest(url, listener);
		AppApplication.instance.requestQueue.add(request);
	}

	public void sendLocalRequest(OnHttpListener listener) {
		listener.onHttpStart();
		List<ArticleModel> articleModels = DataBaseMannager.getInstance().queryFavs(this);
		listener.onResponse(true,"", JSON.toJSONString(articleModels));
	}

	// @Override
	// public void startActivity(Intent intent) {
	// super.startActivity(intent);
	// overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
	// }
	//
	// @Override
	// public void finish() {
	// super.finish();
	// overridePendingTransition(R.anim.actviity_finish_in, R.anim.activity_finish_out);
	// }
}
